/*
 * RCreceiver.h
 *
 *  Created on: Dec 17, 2014
 *      Author: bohni
 */

#ifndef RCRECEIVER_H_
#define RCRECEIVER_H_

#include "Task.h"
#include "config.h"


/* receiver Flags */
#define RC_RECEIVER_FLAG_SYNC					0x01
#define RC_RECEIVER_FLAG_SEQUENCE_COMPLETE 		0x02

#define RC_RECEIVER_FLAG_SYNC_LOST 		 		0x80

/* signal detection defines */
#define RC_RECEIVER_OverrunTime_us				3500

#define RC_RECEIVER_MinHighTime_us				1000
#define RC_RECEIVER_MaxHighTime_us				1700
#define RC_RECEIVER_SyncTime_us					300		// time between two pulses

#define RC_RECEIVER_DETECT_RISING_SLOPE

#ifdef RC_RECEIVER_DETECT_RISING_SLOPE
#define INPUT_CAPURE_POLARITY		TIM_ICPolarity_Rising
#else
#define INPUT_CAPURE_POLARITY		TIM_ICPolarity_Falling
#endif

/* number of stored rec channels */
#define RECEIVER_CHANNELS						5

class RCreceiver: public Task {
public:
	RCreceiver(Status* statusPtr, uint8_t defaultPrio);
	virtual ~RCreceiver();
	void update();
	void RCreceiverIRQ();

private:
	void lowLevelInit();
	void computeValues();
	void sync();

	uint16_t rawReceiverValues[8];

	uint8_t RCreceiverFlags;
	uint8_t currentChannel;


};

#endif /* RCRECEIVER_H_ */
